//养护基地
var vm = new Vue({
	el: '#app',
	data: function() {
		return {
			userList: [{ //模拟用户信息
				"ID": "0",
				"name": "张三",
				"isSenior": true,
				"isAdmin": false
			}, {
				"ID": "1",
				"name": "李四",
				"isSenior": true,
				"isAdmin": false
			}, {
				"ID": "2",
				"name": "王五",
				"isSenior": false,
				"isAdmin": true
			}, {
				"ID": "3",
				"name": "马六",
				"isSenior": false,
				"isAdmin": true
			}]
		}
	},
	mounted: function() {
		var that = this;
		mui.init({});
		mui.ready(function() {
            that.getUserList(); //获取人员列表
		})
	},
	methods: {
        //获取人员列表
        getUserList: function() {
            var that = this;
            var list = [];
            $.getJSON('getUserCheck', {}, function(res) {
                that.userList = res
            })
        },
		save: function() {
			var that = this;
			var seniors = $('input[name="senior"]:checked'); //所有选中的高级人员
			var admins = $('input[name="admin"]:checked'); //所有选中的高级人员
			var seniorsArr = [];
			var adminsArr = [];
			$.each(seniors, function(i, item) {
				var id = $(item).data('id');
				seniorsArr[i] = id;
			})
			$.each(admins, function(i, item) {
				var id = $(item).data('id');
				adminsArr[i] = id;
			})
            if(adminsArr.length==0){
                mui.toast('至少选择一位管理员')
                return false;
            }
			var choseSeniors = seniorsArr.join(','); //选中的高级人员ID字符串集合
			var choseAdmins = adminsArr.join(','); //选中的管理员人员ID字符串集合
			console.log(choseSeniors)
			console.log(choseAdmins)
            $.post('addEventUsers', {
                "eventIds": choseSeniors,
                "adminIds":choseAdmins
            }, function(res) {
                console.log(res)
                mui.toast('保存成功');
                return;
            })
		}
	}
})